package com.tools.module.base.web;

import com.tools.common.config.AbstractController;
import com.tools.common.model.Result;
import com.tools.common.util.DateUtils;
import com.tools.common.util.ShiroUtils;
import com.tools.module.base.entity.BaseClassify;
import com.tools.module.base.service.BaseClassifyService;
import com.tools.module.base.service.impl.UploadFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/base/classify")
public class BaseClassifyController extends AbstractController {

    @Autowired
    private BaseClassifyService classifyService;
    @Autowired
    private UploadFileService uploadFileService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public Result list(BaseClassify classify){
        return classifyService.list(classify);
    }
    /**
     * 查询
     */
    @PostMapping("/get")
    public Result get(Long id){
        return classifyService.get(id);
    }
    /**
     * 保存
     */
    @PostMapping("/save")
    public Result save(@RequestBody BaseClassify classify){
        if (classify.getId()==null){
            classify.setCreateTime(DateUtils.getTimestamp());
            classify.setCreateUid(ShiroUtils.getUserId());
        }
        classify.setUpdateUid(ShiroUtils.getUserId());
        Long aLong = classifyService.queryBySeq(classify);
        if (aLong>0) {
            classifyService.updateSeq(classify);
        };
        return classifyService.save(classify);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public Result delete(Long id){
        return classifyService.delete(id);
    }
}
